﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Bot.Application.Dto;
using Bot.Application.Services;
using Microsoft.AspNetCore.Mvc;

namespace Bot.WebAPI.Controllers
{
    [Route("api/v3/chatbot")]
    [ApiController]
    public class QuickReplyItemsController : ControllerBase
    {

        private readonly IQuickReplyItemAppService _app;
        public QuickReplyItemsController(IQuickReplyItemAppService app)
        {
            this._app = app;
        }

        [HttpGet]
        [Route("quickreplyItems/{id:Guid}")]
        public ActionResult<QuickReplyItemDto> Get([FromRoute] Guid id, [FromQuery] string include)
        {
            QuickReplyItemDto quickReplyItem = _app.Get(id, include);
            return Ok(quickReplyItem);
        }

        [HttpGet]
        [Route("quickreplies/{quickreplyId:Guid}/quickreplyItems")]
        public ActionResult<IEnumerable<QuickReplyItemDto>> GetList([FromRoute] Guid quickreplyId,[FromQuery] string include)
        {
            IEnumerable<QuickReplyItemDto> list = _app.GetList(quickreplyId, include);
            return Ok(list);
        }

        [HttpPut]
        [Route("quickreplyItems/{id:Guid}")]
        public ActionResult<QuickReplyItemDto> Put([FromBody] QuickReplyItemUpdateDto dto)
        {
            QuickReplyItemDto quickReplyItem = _app.Update(dto);
            return Ok(quickReplyItem);
        }

        [HttpPost]
        [Route("quickreplies/{quickreplyId:Guid}/quickreplyItems")]
        public ActionResult<QuickReplyItemDto> Post([FromRoute] Guid quickreplyId, [FromBody] QuickReplyItemCreateDto dto)
        {
            QuickReplyItemDto quickReplyItem = _app.Add(quickreplyId, dto);
            return CreatedAtAction(nameof(Get), new { id = quickReplyItem.Id }, quickReplyItem);
        }

        [HttpDelete]
        [Route("quickreplyItems/{id:Guid}")]
        public ActionResult Delete([FromRoute] Guid id)
        {
            _app.Delete(id);
            return NoContent();
        }
    }
}
